#!/usr/bin/env python
# -*- coding:utf8 -*-
# uncompyle6 version 2.15.1
# Python bytecode 2.7 (62211)
# Decompiled from: Python 2.7.10 (default, Jul  1 2017, 13:36:56) 
# [GCC 4.4.6 20110731 (Red Hat 4.4.6-4)]
# Embedded file name: ./paas/resource/models.py
# Compiled at: 2017-11-16 15:44:28
"""
Tencent is pleased to support the open source community by making 蓝鲸智云(BlueKing) available.
Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
"""
from django.db import models

class Resource(models.Model):
    """
    资源下载
    """
    name = models.CharField(u'名称', max_length=128)
    version = models.CharField(u'版本', max_length=36, blank=True, null=True, default='--')
    size = models.CharField(u'文件大小', max_length=36, blank=True, null=True, default='--')
    display = models.BooleanField(u'是否显示', default=True)
    icon_url = models.CharField(u'下载图标', max_length=256, blank=True, null=True, help_text=u'填写外网地址')
    doc_url = models.CharField(u'文档URL', max_length=256, blank=True, null=True, help_text=u'填写外网地址')
    download_url = models.CharField(u'下载URL', max_length=256, blank=True, null=True, help_text=u'填写外网地址')
    create_time = models.DateTimeField(u'创建时间', auto_now_add=True)

    class Meta:
        db_table = 'paas_resources'
        verbose_name = u'资源下载'
        verbose_name_plural = u'资源下载'

    def __unicode__(self):
        return '<%s-%s>' % (self.name, self.id)

    @property
    def version_display(self):
        return self.version or '--'

    @property
    def size_display(self):
        return self.size or '--'

    @property
    def icon_url_display(self):
        """
        resource icon url
        """
        if not self.icon_url:
            return u'%s.png' % self.name.replace(' ', '_')
        return self.icon_url

    @property
    def download_url_display(self):
        """resource download url
        """
        if not self.download_url:
            return u'%s' % self.name.replace(' ', '_')
        return self.download_url
